using System.Net.Mail;
using Headspring.Training.Domain.Model;
using Headspring.Training.Domain.Model.StateCommands;
using Headspring.Training.Domain.Services;
using NUnit.Framework;
using StructureMap;

namespace Headspring.Training.DataAccess.IntegrationTests
{
	[TestFixture]
	public class WorkflowCoordinatorIntegratedTester
	{
		[Test]
		public void ShouldSendMailMessageAndSmsMessage()
		{
			WorkOrder workOrder = new WorkOrder();
			workOrder.Status = WorkOrderStatus.Cancelled;
			Employee creator = new Employee("", "Homer", "Simpson", "homer@simpson.com");
			Employee assignee = new Employee("", "Marge", "Simpson", "marge@simpson.com");
			assignee.SetAllNotificationPreferencesTo(NotificationType.Both);
			workOrder.Creator = creator;
			workOrder.Assignee = assignee;
			IStateCommand stateCommand = new InProgressToCancelledCommand(workOrder,
			                                                              creator);

			MockSmtpSender sender = new MockSmtpSender();
			MockWirelessSender wirelessSender = new MockWirelessSender();

			ObjectFactory.InjectStub(typeof(ISmtpSender), sender);
			ObjectFactory.InjectStub(typeof(IWirelessSender), wirelessSender);
			IWorkflowCoordinator coordinator = ObjectFactory.GetInstance<IWorkflowCoordinator>();
			coordinator.SendNotification(stateCommand, workOrder);

			Assert.That(sender.SendWasCalled);
			Assert.That(wirelessSender.SendWasCalled);
		}
	}

	internal class MockWirelessSender : IWirelessSender
	{
		public bool SendWasCalled = false;

		public void Send(SmsMessage message)
		{
			SendWasCalled = true;
		}
	}

	internal class MockSmtpSender : ISmtpSender
	{
		public bool SendWasCalled = false;

		public void Send(MailMessage message)
		{
			SendWasCalled = true;
		}
	}
}